﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using becom.Model;
namespace becom.BLL
{
	/// <summary>
	/// oa_family_record
	/// </summary>
	public partial class oa_family_record
	{
		private readonly becom.DAL.oa_family_record dal=new becom.DAL.oa_family_record();
		public oa_family_record()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int record_id)
		{
			return dal.Exists(record_id);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(becom.Model.oa_family_record model)
		{
			dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(becom.Model.oa_family_record model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int record_id)
		{
			
			return dal.Delete(record_id);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string record_idlist )
		{
			return dal.DeleteList(record_idlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public becom.Model.oa_family_record GetModel(int record_id)
		{
			
			return dal.GetModel(record_id);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public becom.Model.oa_family_record GetModelByCache(int record_id)
		{
			
			string CacheKey = "oa_family_recordModel-" + record_id;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(record_id);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (becom.Model.oa_family_record)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<becom.Model.oa_family_record> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<becom.Model.oa_family_record> DataTableToList(DataTable dt)
		{
			List<becom.Model.oa_family_record> modelList = new List<becom.Model.oa_family_record>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				becom.Model.oa_family_record model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new becom.Model.oa_family_record();
					if(dt.Rows[n]["record_id"]!=null && dt.Rows[n]["record_id"].ToString()!="")
					{
						model.record_id=int.Parse(dt.Rows[n]["record_id"].ToString());
					}
					if(dt.Rows[n]["person_id"]!=null && dt.Rows[n]["person_id"].ToString()!="")
					{
						model.person_id=int.Parse(dt.Rows[n]["person_id"].ToString());
					}
					if(dt.Rows[n]["card_id"]!=null && dt.Rows[n]["card_id"].ToString()!="")
					{
					model.card_id=dt.Rows[n]["card_id"].ToString();
					}
					if(dt.Rows[n]["name"]!=null && dt.Rows[n]["name"].ToString()!="")
					{
					model.name=dt.Rows[n]["name"].ToString();
					}
					if(dt.Rows[n]["relationship"]!=null && dt.Rows[n]["relationship"].ToString()!="")
					{
					model.relationship=dt.Rows[n]["relationship"].ToString();
					}
					if(dt.Rows[n]["record_date"]!=null && dt.Rows[n]["record_date"].ToString()!="")
					{
						model.record_date=DateTime.Parse(dt.Rows[n]["record_date"].ToString());
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

